﻿using System.Windows;
using theeg.GeometryWpf;
using theeg.GraphWpf.Models;

namespace theeg.GraphWpf.Views
{
    [TemplateVisualState(Name = "MouseOver", GroupName = "CommonStates")]
    [TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
    public class TransitionPresenter : PresenterBase
    {
        public override IHilbertTreeNode HilbertNode
        {
            get { return Data; }
        }

        public Transition Data
        {
            get { return (Transition)GetValue(DataProperty); }
            set { SetValue(DataProperty, value); }
        }

        public static readonly DependencyProperty DataProperty =
            DependencyProperty.Register("Data", typeof(Transition), typeof(TransitionPresenter), new PropertyMetadata(null));

        public TransitionPresenter()
        {
            DefaultStyleKey = typeof(TransitionPresenter);
        }

        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            if (e.Property == IsMouseOverProperty)
            {
                CoerceMouseOver(Data, IsMouseOver);
            }
        }

        private void CoerceMouseOver(Transition data, bool isMouseOver)
        {
            data.Source.IsHighlighted = isMouseOver;
            data.Target.IsHighlighted = isMouseOver;
        }
    }
}
